using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using eShop.Business;
using eShop.Utility;
using eShop.Model;
using eShop.Business;

public partial class register : SitePublicBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void imbRegister_Click(object sender, EventArgs e)
    {
        try
        {
            if (Page.IsValid)
            {
                User user = new eShop.Model.User();
                user.Profile = new UserProfile();

                user.UserName = tbxPersonalEmailAddress.Text.Trim();
                user.Password = tbxLoginPassword.Text.Trim();

                user.Profile.FirstName = tbxPersonalFirstName.Text.Trim();
                user.Profile.LastName = tbxPersonalLastName.Text.Trim();
                user.Profile.PhoneNumber = tbxContactPhoneNumber.Text.Trim();
                user.Profile.EmailAddress = tbxPersonalEmailAddress.Text.Trim();

                UserManager.CreateNewCustomerUser(user);

                new Email().SendRegistrationEmail(user);
                new Email().SendRegistrationEmailToAdmin(user);
                if (SessionManager.ReturnUrl != null && SessionManager.CheckoutSteps == CheckoutSteps.PreCheckout)
                {
                    string returnUrl = SessionManager.ReturnUrl;
                    SessionManager.ReturnUrl = null;
                    if (UserManager.Login(user.UserName, user.Password, UserLocationType.FrontEnd))
                    {
                        Response.Redirect(returnUrl);
                    }
                }
                else
                {
                    Response.Redirect(CustomSiteMap.RegistrationSuccessful);
                }
            }
        }
        catch (Exception ex)
        {

            uccResponseMessage.SetFailMessage("Registration Failed." + ex.Message);
            uccResponseMessage.Visible = true;
        }
    }
}

